#include <iostream>

using std::cout;
using std::endl;

//可变模板参数
template <typename ...Args>//模板参数包,...位于Args的左边，称为打包
void display(Args ...args)//函数参数包,...位于args的左边，称为打包
{
    cout << "sizeof...(Args) = " << sizeof...(Args) << endl;
    cout << "sizeof...(args) = " << sizeof...(args) << endl;
    /* cout << "Args... = " << Args... << endl;//error */
    /* cout << "args... = " << args... << endl;//error */
}

//template <typename T1, typename T2, typename T3, typename T4>
//display(T1 x, T2 y, T3 a, T4 b)
//T1 x = 1, T2 y = "hello", T3 a = 3.3, T4 b = true
//T1 = int, T2 = const char *, T3 = double, T4 = bool
void test()
{
    display();
    display(1, "hello", 3.3, true);
}

void print()
{
    cout << endl;
}

//n个参数
//1 n - 1
template <typename T, typename ...Args>
void print(T x, Args ...args)
{
    cout << x << "  ";
    //print(args1, args2, args3,...)
    print(args...);//...位于args的右边，称为解包
}

void test2()
{
    //cout << endl;
    print();

    //cout << 1 << "  ";
    //print("hello", 3.4, true, 100)
    //   cout << "hello" << "  ";
    //   print(3.4, true, 100);
    //     cout << 3.4 << "  ";
    //     print(true, 100);
    //        cout << 1 << "  ";
    //        print(100);
    //           cout << 100 << " ";
    //           print();
    //             cout << endl;
    print(1, "hello", 3.4, true, 100);
}

int sum()
{
    return 0;
}

template <typename T, typename ...A>
int sum(T x, A ...a)
{
    return x + sum(a...);
    // return 1 + sum(2, ... 10)
    // return 1 + 2 + sum(3, ..., 10)
    // return 1 + 2 +  + 3 + sum(4, ..., 10)
    // ...
    // return 1 + 2 + 3 + ... + 9 + sum(10);
    // return 1 + 2 + 3 + ... + 9 + 10 + sum();
}

void test3()
{
    cout << "sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) = "
         << sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) << endl;

    //N 0 1 2 3 10000  10000
    cout << sum(1) << endl;
    cout << sum() << endl;
}

int main(int argc, char **argv)
{
    test3();
    return 0;
}

